<?php
include_once "db.php";
include_once "checksession.php"; 
include_once "auth_permissions.php";

authorize("admin");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Modify Helpdesk Users</title>
<link href="meta-style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include_once "topnav.php";
?>
<p class="title">Helpdesk Users</p>
<form action="add_user.php" method="post">
<table width="535" border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="4" bgcolor="#999999"><strong>Add new User:</strong></td>
</tr>
  <tr>
    <td width="260" align="right">Name: 
      <INPUT NAME="name" TYPE="TEXT" id="name" value="" SIZE="35"></td>
	<td width="261" align="right">Username: 
	  <INPUT NAME="username" TYPE="TEXT" id="username" value="" SIZE="35"></td>
	</tr>
	<tr>
	<td align="right">Email: 
	  <INPUT NAME="email" TYPE="TEXT" id="email" value="" SIZE="35"></td>
	<td align="right">Password: 
	  <INPUT NAME="password" TYPE="password" id="password" value="" SIZE="35"></td>
    </tr>
	<tr>
	<td align="right">User Type: 
	  <INPUT NAME="status" TYPE="TEXT" id="status" value="" SIZE="35"></td>
	<td align="right">Admin=1, User=2 Inactive=0</td>
    </tr>
</table><br/>
<input type=SUBMIT value="Add New" name="SUBMIT">
</form>
<table width="700" border="1" cellpadding="3" cellspacing="0" bordercolor="#666666">
 
   <tr align="center" bgcolor=#999999>
		<td><strong>ID</strong></td>
		<td><strong>Name</strong></td>
		<td><strong>User Name</strong></td>
		<td><strong>Email Address</strong></td>
		<?php
		$auth_query = mysql_query("select `name`, `value` FROM `helpdesk_permissions`");
		while($permission = mysql_fetch_array($auth_query))
		{
		?>
		<td><strong><?php echo $permission['name']; ?></strong></td>
		<?php
		}
		?>
		<td><strong>Action</strong></td>
   </tr>
	
	<?php
	$types = mysql_query("select * FROM `helpdesk_users` ORDER BY `status` DESC");
	while($results = mysql_fetch_array($types)) 
	{
	?>
		<tr align="left">
			<td>
				<?php echo $results['HD_user_ID']; ?>
			</td>
			<td>
				<?php echo $results['name']; ?>
			</td>
			<td>
				<?php echo $results['username']; ?>
			</td>
			<td>
				<?php echo $results['email']; ?>
			</td>
			<?php
			$auth_query = mysql_query("select `name`, `value` FROM `helpdesk_permissions`");
			while($permission = mysql_fetch_array($auth_query))
			{
			?>
			<td>
				<?php echo auth_check_user($results['HD_user_ID'], $permission['name']) ? "1" : " "; ?>
			</td>
			<?php
			}
			?>
			<td>
				<a href="edit_users.php?HD_user_ID=<?php echo $results[HD_user_ID]; ?> ">Edit</a> | 
				<a href="delete_user.php?HD_user_ID=<?php echo $results[HD_user_ID]; ?>">Delete</a>
			</td>
	<?php
	}
	?> 
</table>
 <p><a href="index.php">Back to Main Menu</a></p>
</body>
</html>
